<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
  <head>
    <title>所有记录</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/timeago.js"></script>
  </head>
  
  <body>
    <%@include file="include/topbar.jsp" %>

	<div class="container" style="margin-top: 60px">
			<div class="row">
				<jsp:include page="include/left.jsp">
					<jsp:param value="contact" name="tag"/>
				</jsp:include>
	<div class="span9">
			
			<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0" class="breadcrumb">
				<li class="active">
					<a href="task.html"><i class="icon-user"></i>联系人</a>
				</li>
			</ul>
			<div class="wall">
				<address>
					<h3>${cnm.contact.name}</h3>
					<p>${cnm.contact.companyname}</p>
					<small>手机</small> ${cnm.contact.moblie}<br>
					<small>固话</small> ${cnm.contact.tel}<br><br>
					<small>邮箱</small> ${cnm.contact.email}<br>
					<small>地址</small> ${cnm.contact.address}<br><br>
					<small>主页</small> <a href="${cnm.contact.website}">${cnm.contact.website}</a><br>
					<small>微博</small> <a href="${cnm.contact.weibo}">@${cnm.contact.weibo}</a><br>
					<small>简介</small> ${cnm.contact.content}<br/>
				</address>
				<div class="line">记录</div>
					<textarea rows="3" class="span5"></textarea>
					<br>
					<button id="sendnote">发布</button>
				<div id="log">
				<c:forEach var="note" items="${cnm.list}">
					<blockquote>
					  ${note.content}
					  <small>${note.name}发布于<abbr class="timeago" title="${note.createTime}" rel="${note.id}"></abbr></small>
					</blockquote>
				</c:forEach>
				</div>
				<a href="contact.jspx">←返回联系人列表</a>
				</div>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		$(function() {
			$("abbr.timeago").timeago();
			
			var id = "${cnm.contact.id}";
			var name = "${cnm.contact.name}";
			$("#sendnote").click(function() {
				var note = $("textarea").val();
				if(note.trim() != "" && id.trim() != "") {
					var abbr = $("#log blockquote:first-child small abbr");
					var lastTime = abbr.attr("title");
					var noteId = abbr.attr("rel");
					if(!lastTime) {
						lastTime = "0";
						noteId = "0";
					}
					
					$.ajax({
						url : 'contactnote.jspx',
						type : 'POST',
						dataType: 'json',
						data : {
							id : id,
							time : lastTime,
							note : note,
							noteid : noteId,
							name : name
						},
						success : function(data) {
							$("textarea").val("");
							$.each(data, function(i, n) {
								var small = $("<small>").text(n.name + "发表于");
			  					var abbr = $("<abbr>").attr({"class" : "timeago", "title" : n.createTime, "rel" : n.id});
			  					small.append(abbr);
			  					$("<blockquote>").text(n.content).append(small).prependTo($("#log"));
							});
							
							$("abbr.timeago").timeago();
						}
					});
				}
			});
		});
	</script>
</body>
</html>
